package com.vf.admin.miaodong.controller;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCashWithdrawalMoney;
import com.vf.admin.miaodong.service.AfterCashWithdrawalMoneyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.vf.admin.utils.StringEx.isNull;

/**
 * 提现金额管理
 * @author anxiang
 * @version 1.0.0
 * @ClassName AppCashWithdrawalMoneyController.java
 * @Description TODO
 * @createTime 2021年11月06日 16:22:00
 */
@Controller
@RequestMapping("/after/txmoney")
public class AfterCashWithdrawalMoneyController extends BaseController{

    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    AfterCashWithdrawalMoneyService afterCashWithdrawalMoneyService;

    /**
    * 提现金额列表
    * @Param: [splitPageBean]
    * @return: java.lang.String
    * @Author: zhouyunyi
    * @Date: 2021/07/6
    * @Time: 16:29
    */
    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean,Integer leixing){
        try{
            Map<String,Object> map = new HashMap<>();
            map.put("leixing",leixing);
            List<AppCashWithdrawalMoney> list = afterCashWithdrawalMoneyService.list(map,splitPageBean);
            Map<Integer,String> lxmap = Constants.getShiFouStateMap();
            request.setAttribute("list",list);
            request.setAttribute("splitPage",splitPageBean);
            request.setAttribute("lxmap",lxmap);
            request.setAttribute("leixing",leixing);
            return this.sucess("/web/after/txmoney/list");
        }catch (Exception e){
            logger.error("提现金额列表异常",e);
            return this.error("系统繁忙");
        }
    }

    /**
    * 详情
    * @Param: [id]
    * @return: java.lang.String
    * @Author: zhouyunyi
    * @Date: 2021/07/6
    * @Time: 16:33
    */
    @RequestMapping("/detail")
    public String detail(Integer id){
        try{
            AppCashWithdrawalMoney cashWithdrawalMoney = afterCashWithdrawalMoneyService.get(id);
            request.setAttribute("txmoney",cashWithdrawalMoney);
            Map<Integer,String> lxmap = Constants.getShiFouStateMap();
            request.setAttribute("lxmap",lxmap);
            return this.sucess("/web/after/txmoney/edit");
        }catch (Exception e){
            logger.error("查看详情异常",e);
            return this.error("系统繁忙");
        }
    }

    /**
    * 编辑
    * @Param: [cashWithdrawalMoney]
    * @return: com.vf.admin.common.entity.Result
    * @Author: zhouyunyi
    * @Date: 2021/07/6
    * @Time: 16:35
    */
    @RequestMapping("/save")
    @ResponseBody
    public Result save(AppCashWithdrawalMoney cashWithdrawalMoney){
        try{
            if(isNull(cashWithdrawalMoney.getMoney())){
                return this.errorJSON("金额不能为空");
            }
            if(isNull(cashWithdrawalMoney.getId())){
                //新增
                cashWithdrawalMoney.setLeixing(cashWithdrawalMoney.getLeixing() == null ? Constants.shiFou_STATE_FOU : cashWithdrawalMoney.getLeixing());
                cashWithdrawalMoney.setCreatetime(new Date());
                afterCashWithdrawalMoneyService.save(cashWithdrawalMoney);
            }else {
                //修改
                AppCashWithdrawalMoney txmoney = afterCashWithdrawalMoneyService.get(cashWithdrawalMoney.getId());
                txmoney.setLeixing(cashWithdrawalMoney.getLeixing() == null ? Constants.shiFou_STATE_FOU : cashWithdrawalMoney.getLeixing());
                txmoney.setMoney(cashWithdrawalMoney.getMoney());
                txmoney.setGoldCoin(cashWithdrawalMoney.getGoldCoin());
                txmoney.setImage(cashWithdrawalMoney.getImage());
                afterCashWithdrawalMoneyService.save(txmoney);
            }
            return this.sucessJSON("保存成功");
        }catch (Exception e){
            logger.error("编辑提现金额信息异常",e);
            return this.errorJSON("系统繁忙");
        }
    }

}
